package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.ColltDelayCaseAppDao;
import com.fdb.efp.nls.service.domain.ColltDelayCaseApp;
import com.fdb.efp.nls.service.facade.ColltDelayCaseAppService;
import com.fdb.efp.nls.service.vo.ColltDelayCaseAppVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 委外催收延案申请表	<p>
 * @author ligm
 * @date 2019-08-27
 */
@Service("colltDelayCaseAppService")
public class ColltDelayCaseAppServiceImpl implements ColltDelayCaseAppService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(ColltDelayCaseAppServiceImpl.class);

	@Autowired
	private ColltDelayCaseAppDao colltDelayCaseAppDao;
	
	/**
	 * 新增操作
	 */
	public int insertColltDelayCaseApp(ColltDelayCaseAppVO inColltDelayCaseAppVo) {
		logger.debug("当前新增数据为:"+ inColltDelayCaseAppVo.toString());
		int num = 0;
		try {
			ColltDelayCaseApp colltDelayCaseApp = new ColltDelayCaseApp();
			beanCopy(inColltDelayCaseAppVo, colltDelayCaseApp);
			num = colltDelayCaseAppDao.insertColltDelayCaseApp(colltDelayCaseApp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(ColltDelayCaseAppVO inColltDelayCaseAppVo) {
		logger.debug("当前删除数据条件为:"+ inColltDelayCaseAppVo);
		int num = 0;
		try {
			ColltDelayCaseApp colltDelayCaseApp = new ColltDelayCaseApp();
			beanCopy(inColltDelayCaseAppVo, colltDelayCaseApp);
			num = colltDelayCaseAppDao.deleteByPk(colltDelayCaseApp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inColltDelayCaseAppVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(ColltDelayCaseAppVO inColltDelayCaseAppVo) {
		logger.debug("当前修改数据为:"+ inColltDelayCaseAppVo.toString());
		int num = 0;
		try {
			ColltDelayCaseApp colltDelayCaseApp = new ColltDelayCaseApp();
			beanCopy(inColltDelayCaseAppVo, colltDelayCaseApp);
			num = colltDelayCaseAppDao.updateByPk(colltDelayCaseApp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inColltDelayCaseAppVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public ColltDelayCaseAppVO queryByPk(ColltDelayCaseAppVO inColltDelayCaseAppVo) {
		
		logger.debug("当前查询参数信息为:"+ inColltDelayCaseAppVo);
		try {
			ColltDelayCaseApp queryColltDelayCaseApp = new ColltDelayCaseApp();
			beanCopy(inColltDelayCaseAppVo, queryColltDelayCaseApp);
			ColltDelayCaseApp queryRslColltDelayCaseApp = colltDelayCaseAppDao.queryByPk(queryColltDelayCaseApp);
			if (Objects.nonNull(queryRslColltDelayCaseApp)) {
				ColltDelayCaseAppVO outColltDelayCaseAppVo = beanCopy(queryRslColltDelayCaseApp, new ColltDelayCaseAppVO());
				logger.debug("当前查询结果为:"+ outColltDelayCaseAppVo.toString());
				return outColltDelayCaseAppVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<ColltDelayCaseAppVO> queryAllOwner(ColltDelayCaseAppVO colltDelayCaseAppVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<ColltDelayCaseAppVO> list = null;
		try {
			List<ColltDelayCaseApp> colltDelayCaseApps = colltDelayCaseAppDao.queryAllOwnerByPage(colltDelayCaseAppVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ colltDelayCaseApps.size());
			pageSet(colltDelayCaseApps, colltDelayCaseAppVo);
			list = (List<ColltDelayCaseAppVO>) beansCopy(colltDelayCaseApps, ColltDelayCaseAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<ColltDelayCaseAppVO> queryAllCurrOrg(ColltDelayCaseAppVO colltDelayCaseAppVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<ColltDelayCaseApp> colltDelayCaseApps = colltDelayCaseAppDao.queryAllCurrOrgByPage(colltDelayCaseAppVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+colltDelayCaseApps.size());
		List<ColltDelayCaseAppVO> list = null;
		try {
			pageSet(colltDelayCaseApps, colltDelayCaseAppVo);
			list = (List<ColltDelayCaseAppVO>) beansCopy(colltDelayCaseApps, ColltDelayCaseAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<ColltDelayCaseAppVO> queryAllCurrDownOrg(ColltDelayCaseAppVO colltDelayCaseAppVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<ColltDelayCaseApp> colltDelayCaseApps = colltDelayCaseAppDao.queryAllCurrDownOrgByPage(colltDelayCaseAppVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ colltDelayCaseApps.size());
		List<ColltDelayCaseAppVO> list = null;
		try {
			pageSet(colltDelayCaseApps, colltDelayCaseAppVo);
			list = (List<ColltDelayCaseAppVO>) beansCopy(colltDelayCaseApps, ColltDelayCaseAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	@Override
	public List<ColltDelayCaseAppVO> queryByDelayCaseApp(List<String> delayCaseApps) {
		List<ColltDelayCaseAppVO> list = null;
		try {
			List<ColltDelayCaseApp> colltDelayCaseAppList = colltDelayCaseAppDao.queryByDelayCaseApps(delayCaseApps);
			list = (List<ColltDelayCaseAppVO>) beansCopy(colltDelayCaseAppList, ColltDelayCaseAppVO.class);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("根据延案申请流水号集查询信息发生异常!", e);
		}
		return list;
	}

	@Override
	public List<ColltDelayCaseAppVO> queryByStatus(List<String> delayCaseApps){
		List<ColltDelayCaseAppVO> list = null;
		try {
			List<ColltDelayCaseApp> colltDelayCaseAppList = colltDelayCaseAppDao.queryByStatus(delayCaseApps);
			list = (List<ColltDelayCaseAppVO>) beansCopy(colltDelayCaseAppList, ColltDelayCaseAppVO.class);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("根据延案申请流水号集查询信息发生异常!", e);
		}
		return list;
	}
}
